<template>
  <div class="login-page">
    <!-- 登陆输入框 -->
    <van-cell-group>
      <van-field
        v-model="username"
        required
        clearable
        label="用户名"
        right-icon="question-o"
        placeholder="请输入用户名"
        @click-right-icon="$toast('question')"
      />
      <van-field v-model="password" type="password" label="密码" placeholder="请输入密码" required/>

    </van-cell-group>
    <van-button type="primary" @click="submitLogin">登陆</van-button>
    <a href="#">免费注册</a>
    <router-view></router-view>
  </div>
</template>
<script>
import qs from 'qs'
import { mobile } from '@/api'
export default {
  data () {
    return {
      username: '',
      password: ''
    }
  },
  methods: {
    submitLogin () {
      mobile.getLogin({ username: this.username, password: this.password })
        .then(res => {
          console.log(res)
          if (res.data.success) {
            this.$toast.success('登陆成功')
            location.href = qs.parse(location.href.split('?')[location.href.split('?').length - 1]).repath
          } else {
            this.$toast.fail(res.data.message)
          }
        })
    }
  }
}
</script>

<style lang="scss" scoped>
.van-button {
      width: 100%;
    height: 35px;
    line-height: 35px;
    margin: 20px 0;
}
a {
  font-size: 12px;
}

</style>
